<template>
	<om-page title="登录">
		<view class="padding-xl text-center text-xxl bg-steelblue">设置新密码</view>
		<view class="content">
			<!-- #ifdef H5 || APP-PLUS -->
			<om-wing-blank>
				<view class="input-group">
					<view class="input-row border">
						<text class="title">密码:</text>
						<m-input type="password" displayable v-model="pwd" placeholder="输入密码"></m-input>
					</view>
					<view class="input-row">
						<text class="title">确认密码:</text>
						<m-input type="password" displayable v-model="repwd" placeholder="再次输入密码"></m-input>
					</view>
				</view>
				<om-white-space></om-white-space>
				<om-wing-blank class="tui-flex justify-end">
					<text class='text-sm bg-grey light'>密码规则：8-20位数字与字母组合，且至少包含一个字母</text>
				</om-wing-blank>
				<view class="btn-row"><button type="primary" class="primary" @tap="bindConfirm">确认</button></view>
				<om-wing-blank class="tui-flex justify-end">
					<view @click="login" class='cu-tag radius bg-grey'>登录</view>
				</om-wing-blank>
			</om-wing-blank>
			<!-- #endif -->
		</view>
	</om-page>
</template>

<script>
import md5 from '@/static/js/md5.js';
	import {ignoreHtml, errorModal,confirmModal } from 'static/js/common.js'
const app = getApp();
export default {
	data() {
		return {
			pwd:"",
			repwd:"",
			idcard:"",
			verifyCode:""
		};
	},
	onLoad(e) {
		if(!e.fromSetting){
			if(!e.idcard){
				uni.redirectTo({
					url:"./forgetpwd"
				})
			}
			if(!e.verifyCode){
				uni.redirectTo({
					url:"./forgetpwd"
				})
			}
			this.idcard = e.idcard
			this.verifyCode = e.verifyCode
		}
	},
	methods: {
		login(){
			uni.reLaunch({
				url:"../login/login"
			})
		},
		bindConfirm(){
			if(!this.pwd){
				this.om.toast("请输入密码")
				return
			}
			if(!this.repwd){
				this.om.toast("请确认密码")
				return
			}
			if(!this.idcard || !this.verifyCode){
				errorModal(this,"验证失败","身份验证已失效，请重新验证身份",function(){
					uni.redirectTo({
						url:"./forgetpwd"
					})
				})
				return
			}
			let _that = this
			this.om.request("loginCenter/updatePwd",{
				idcard:this.idcard,
				verifyCode:this.verifyCode,
				newPwd:md5.hex_md5(this.pwd.toLowerCase()),
				rePwd:md5.hex_md5(this.repwd.toLowerCase())
			}).then(res=>{
				if(res.succeed){
					confirmModal(_that,"SUCCESS","密码修改成功",function(){
						uni.reLaunch({
							url:"../login/login"
						})
					})
				}else{
					_that.om.toast(ignoreHtml(res.msg))
				}
			})
			
		}
	}
};
</script>

<style>
	.forgetPwd{
		text-align: right;
		font-size: 14px;
		padding-top: 15px;
	}
	.forgetPwd a{
		text-decoration: none;
		color: #0faeff;
	}
</style>
